﻿using UnityEngine;
using System.Collections;

public class laser : MonoBehaviour {

	// Use this for initialization
	
	float distancia;
	float timer1;
	float timer2;
	
	void Start () {
	
		distancia = 0.001f;
	}
	
	// Update is called once per frame
	void FixedUpdate () {
		
		
		if(timer1 > 5.0f)
		{
			if(timer2 <5.0f)
			{
				timer2 += Time.deltaTime;
				distancia = 5.0f;
			}
			else
			{
				timer1 = 0;
				timer2 = 0;
				distancia = 0.001f;
			}
			
		}
		else timer1 += Time.deltaTime;

		
		Debug.DrawRay(transform.position, -Vector3.up*distancia, Color.green);		
		
		RaycastHit hit;
		
        if (Physics.Raycast(transform.position, -Vector3.up, out hit, distancia))
        {  
			if(hit.transform.gameObject.CompareTag("Player1"))
			{
				Debug.Log("Muerto por laser");
				GameObject.FindWithTag("GameManager").GetComponent<gameManager>().morir();
			}
		}
		
		
	
	}
	
	
}
